<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta http-equiv="Pragma"  content="no-cache"  /> 
<title>我的易安</title> 
<%@ include file="/user_comm.jsp"%>

<link rel="stylesheet"	href="http://a.tbcdn.cn/apps/sell/1.0/publish_detail_ke.css?t=20110128editor.css" />
<link href="<%=request.getContextPath()%>/css/prop.css" type="text/css" rel="stylesheet"/>
	<script language="JavaScript">
	  var contactList=null;
	  var selUserId=null;
	  var selCompanyName=null;

	  $(document).ready(function(){
	  	$("form *").autohelp("#autohelp");
	    $("#busiInfo_add").validate();
	    if($d("txtRecvUserid").value != ''){//如果收货方账户代码不能空，则验证收货方
	    	checkUserId($d("txtRecvUserid").value,false);
	    }
	    //loadContact();//加载通讯录
	  });
	  
	  function previewImage(vSpanId,fileId){
	  	var imgName=vSpanId;
	  	var imgId=$d(fileId).value;
	  	$(imgName).html('');   
		    var newPreview =$(imgName)[0];     
			var imgDiv = document.createElement("div");
			document.body.appendChild(imgDiv);
			imgDiv.style.width = "100%";
	        imgDiv.style.height = "100%";   
	        imgDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)";      
	        imgDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgId;
			newPreview.appendChild(imgDiv);	
	  }
	
		var checkUserFlag=true;
		var checkSeqFlag=true;
		function carrierTypeChange(){
			if($d("carrierType").value=="1"){
				$d("lb_carrierNo").innerHTML="柜&nbsp;&nbsp;&nbsp;号：";
				$d("tr_size").style.display="block";
				//$d("lb_carrierSize").style.display="block";
				//$d("carrierSize").style.display="block";
			}else{
				$d("lb_carrierNo").innerHTML="车&nbsp;牌&nbsp;号：";
				$d("tr_size").style.display="none";
				//$d("lb_carrierSize").style.display="none";
				//$d("carrierSize").style.display="none";
			}
		}
	
		//inputFlag 是否为手动输入的账户代码
		function checkUserId(userIdVal,inputFlag){
		    checkUserFlag=false;
			$d("recvCompanyid").value = "";
			if(userIdVal==""){
				//$d("recvUsername").innerHTML="请输入收货方账户代码";
				$d("recvUsername").innerHTML="";
				return;
			}
			
			var index=userIdVal.indexOf("-");
			if(index==-1){
				$d("recvUsername").innerHTML="收货方账户代码不正确";
				return;
			}else{
				var strArr=userIdVal.split("-");
				if(strArr.length==2){
					var params = {userIdVal:userIdVal};
					$.ajax({type: "POST",
						   dataType: "json",
					       url: "ajaxUser_checkUserId.do",
					       data: params,
					       async: true,
					       success: function(result){
							 if(result.userIdExist=="false"){
							  	recvUsername.innerHTML="账户代码不存在";
							 }else{
							 	checkUserFlag=true;
							 	$d("recvUsername").innerHTML=result.companyInfo.companyName;
							 	$d("recvCompanyid").value = result.companyInfo.companyId;
								$d("txtRecvUserid").value=result.userInfo.userId;
							 }
						  }
						},"json");
				}else{
					$d("recvUsername").innerHTML="不存在的收货方";
				}
			}
		}
		
		function checkValid(txtValidate){
			var seqId=txtValidate.value;
			if(seqId==""){
				$d("seqIdError").innerHTML="请输入封条号码";
				return;
			}
			var params = {
					seqId:seqId
					};
			$.ajax({type: "POST",
			       url: "ajax_findValid.html",
			       data: params,
			       async: true,   
			       success: function(result){
					 var validate=result.validate;
					 if(validate != null){
					  	var status=validate.status;
					  	if(result.retcode == "0000"){
					  		seqIdError.innerHTML="";
					  		checkSeqFlag=true;
					  	}else{
					  		checkSeqFlag=false;
					  		seqIdError.innerHTML=result.retmsg;
					  	}
					 }else{
					 	checkSeqFlag=false;
					 	seqIdError.innerHTML="封条不存在";
					 }
				  }
				},"json");
		}
		
		//----------------通讯录----------------
		function showContact(){
			var arrretu  = new Array();
			var winFeatures="dialogHeight:400px;dialogWidth:660px;edge:Raised;center:Yes;help:No;resizable:No;status:No;";
			var url = "listContact.do";
			retArr = window.showModalDialog(url,"", winFeatures);
			if(retArr ==null || (!retArr)){
				return false;
			}else{
				//只返回userId,其他信息再实时查询
				var strArr=retArr[0].split("-");
				$d("txtRecvUserid").value = retArr[0].toString();
				$d("recvUsername").innerHTML = retArr[1].toString(); //公司名称
				//实时查询，防止关联账户已被删除
				checkUserId(retArr[0].toString(),false);
				return true;
			}
		}
		
		//Impromptu 模式对话框
		function showContact2(){
			var txt=$d("div_contact").innerHTML;
			$.prompt(txt,{
				submit: mycallbackform,
				buttons: { 确定: true, 取消: false }
			});
		}
		function loadContact(){
			var params = {};
			$.ajax({type: "POST",
		       url: "ajaxContact_loadContact.do",
		       data: params,
		       async: true,
		       success: function(result){
				contactList = result.contactList;
				var groupHtml="";
				for(var i=0;i<contactList.length;i++){
					var group=contactList[i].group;
					groupHtml +="<a href='#' onclick=\"viewMember("+group.id+");\">"+group.groupName+"("+group.count+")</a><br/>";
				}
				$("#spanGroups").html(groupHtml);
				viewMember(0);//显示所有
			  }
			},"json");
		}
		
		function viewMember(groupId) {
			for(var i=0;i<contactList.length;i++){
				var group=contactList[i].group;
				if(group.id==groupId){
					var memberList = contactList[i].memberList;   
					if(memberList.length==0){   
					    $("#tb_memberList").html("<tr><td>没有联系人在分组中</td></tr>");
					    return;
					}
					var result="<thead>"
					result += "<tr class='tr_title'>";
					result += "<td align='center'></td>";
					result += "<td width='110'>账户代码</td>";
					result += "<td >账户名称</td>";
					result += "<td >姓名</td>";
					result += "</tr>";
					result += "</thead>";
					result += "<tbody>";
					//这里的order[i]就相当于list中的order,起属性也是一一对应的   
					for(var j=0;j<memberList.length;j++) {   
					    result += "<tr>";   
					    result += "<td align='center' width='30'><input name='chkSon' id='"+memberList[j].id+"' type='checkbox' value='"+memberList[j].id+"' onclick=\"selectRow("+memberList[j].id+",'"+memberList[j].relateUserid+"','"+memberList[j].relateCompanyName+"')\"></td>";
					    result += "<td>"+memberList[j].relateUserid+"</td>";   
					    result += "<td>"+memberList[j].relateCompanyName+"</td>";
					    result += "<td>"+memberList[j].relateName+"</td>";
					    result += "</tr>";   
					}
					result += "</tbody>";
					$("#tb_memberList").html(result);
					break;
				}
			}
		}
		
		function selectRow(memberId,userId,companyName){
			var arrSon = document.getElementsByName('chkSon');
		 	var curChkbox = document.getElementById(memberId);
		 	if(curChkbox.checked==true){
			 	for(var i=0; i<arrSon.length; i++) {
			 		if(arrSon[i].value != memberId){
			     		arrSon[i].checked = false;
			     	}
			 	}
			 	curChkbox.checked=true;
			 	selUserId=userId;
				selCompanyName=companyName;
		 	}else{
		 		selUserId='';
				selCompanyName='';
			}
		}
		
		function selectOK()
		{
			if(selUserId=='' || selUserId==null)
			{
				alert("请选择收货方账户");
				return;
			}
			var obj=new Array(selUserId,selCompanyName);
			window.returnValue = obj;
			window.close();
		}
		
		function mycallbackform(v,m,f){
			var selDeptid=$('#selDeptid').val();
			if(selDeptid == "-1"){
				alert("请选择封条所属部门");
				return false;
			}
			
			if(v != undefined)
			$.prompt(v +' ' + f.alertName);
		}
		
		function checkSubmit(){
			if(checkUserFlag==false){
				alert("请输入正确的收货方");
				return false;
			}
			
			if(checkSeqFlag==false){
				alert("该封条不可用，请输入其他封条号码");
				return false;
			}
			$('#busiInfo_add').submit();
			return true;
		}
	</script>
	
</head> 
<body> 
<%@ include file="/user_top.jsp"%> 
<div class="realCer"> 
<!--导航--> 
<!--主体部分start--> 
<div class="realMain clearfix mt10"> 
 <%@ include file="/user_menu.jsp"%> 
<div class="realRight ml10 Buyer"> 
	<div class="mybox"> 
		 <div class="mytit">货物发送业务单（改成弹出DIV）</div> 
		   <div class="con Orbuy"> 
		   <s:form name="formpage" action="busiInfo_add" namespace="/"	method="POST" enctype="multipart/form-data">
			<div align="left">
				<%@ include file="/messages.jsp"%>
				<s:token>
				</s:token>
				<s:hidden name="busiInfo.busiNo" value="%{#request.busiInfo.busiNo}" />
				<table class="basicInfor">
					<tr>
						<th>
							发货方：
						</th>
						<td class="fc9">
							&nbsp;${sendUsername }
						</td>
					</tr>
					<tr>
						<th>
							<label for="txtRecvUserid">
								收货方：
							</label>
						</th>
						<td class="fc9">
							&nbsp;<span class="at_text t_1_d">
							<input id="txtRecvUserid" name="busiInfo.recvUserid" type="text"  size="30"
								maxlength="40"  value="${busiInfo.recvUserid }" onblur="checkUserId(this.value,true);" />
							</span>
							<input type="button" id="selRecvUserBtn" value="选择收货方"
								onclick="javascript:showContact();" />
						</td>
					</tr>
					<tr id="tr_recvInfo" style="display:none">
						<th>
						</th>
						<td>
							&nbsp;<input type="hidden" id="recvCompanyid" name="busiInfo.recvCompanyid"
								value="${busiInfo.recvCompanyid }" />
							<span id="recvUsername" />
						</td>
					</tr>

					<tr>
						<th>
							<label for="seqId">
								封条号码：
							</label>
						</th>
						<td>
							&nbsp;<span class="at_text t_1_d"><input name="busiInfo.seqId" id="seqId" type="text" size="30"
								maxlength="40" value="${busiInfo.seqId }"
								onblur="checkValid(this);" />
							<span id="seqIdError"></span>
							</span>
						</td>
					</tr>
					<tr>
						<th>
							加载类型：
						</th>
						<td>
							&nbsp;<select name="busiInfo.carrierType" id="carrierType" style="width:202px"
								onchange="carrierTypeChange();">
								<option value="1">
									集装箱
								</option>
								<option value="2">
									货&nbsp;&nbsp;&nbsp;车
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>
							<label id="lb_carrierNo" for="carrierNo">
								柜&nbsp;&nbsp;&nbsp;&nbsp;号：
							</label>
						</th>
						<td>
							&nbsp;<span class="at_text t_1_d"><input id="carrierNo" name="busiInfo.carrierNo" id="carrierNo" size="30"
								type="text" maxlength="40" 
								value="${busiInfo.carrierNo}" title="*必填" />
							</span>
						</td>
					</tr>
					<tr id="tr_size">
						<th>
							<label id="lb_carrierSize" for="carrierSize">
								货柜尺寸：
							</label>
						</th>
						<td>
							&nbsp;<span class="at_text t_1_d"><input name="busiInfo.carrierSize" id="carrierSize" type="text" size="30"
								maxlength="40" value="${busiInfo.carrierSize}" /></span>
						</td>
					</tr>

					<tr>
						<th>
							<label for="goodsInfo">
								货物描述： 
						</th>
						<td>
							&nbsp;<span class="at_text t_1_d">
							<input id="goodsInfo" name="busiInfo.goodsInfo" type="text"
								maxlength="40" size="30"  value="${busiInfo.goodsInfo}"
								title="*必填" />
							</span>	<!--<em>*</em>-->
						</td>
					</tr>
					<tr>
						<th>
							<label for="goodsNum">
								数&nbsp;&nbsp;&nbsp;&nbsp;量： 
						</th>
						<td>
							&nbsp;<span class="at_text t_1_d"><input name="busiInfo.goodsNum" type="text" id="goodsNum" size="30"
								 title="*必填" value="${busiInfo.goodsNum}" /></span><!--<em>*</em>-->
						</td>
					</tr>

					<tr>
						<th valign="top">
							<label for="googsDetail">
								详细信息：
							</label>
						</th>
						<td>
							<textarea name="busiInfo.goodsDetail" id="googsDetail" cols="50"
								rows="5" style="width: 500px; height: 80px;">${busiInfo.goodsDetail }</textarea>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top">
							上传图片：
						</td>
						<td>
							<table align="center" width="600">
								<tr>
									<td>
										<div>
											<span> <!-- 
										<div style="position: absolute; right: 35px; color: #f60;">
											上传1200px*1200px以上的图片，即可在宝贝详情页面提供图片放大功能
										</div>
										 -->
											<div id="J_UploadPicTab" class="upload-manager upload-pic">
											<ul class="tabs">
												<li class="selected">
													<span><a href="#" title="" class="J_DetectTrigger">上传图片</a> </span>
												</li>
											</ul>
													<div class="panel panel-local">
														<div class="pic-manager">
															<div class="side">
																<div></div>
																<ul>
																	<li class="s1">
																		<a href="javascript:;">d1</a>
																	</li>
																	<li class="s2">
																		<a href="javascript:;">d2</a>
																	</li>
																	<li class="s3">
																		<a href="javascript:;">d3</a>
																	</li>
																	<li class="s4">
																		<a href="javascript:;">d4</a>
																	</li>
																	<li class="s5">
																		<a href="javascript:;">d5</a>
																	</li>
																</ul>
															</div>
															
															<div class="main">
																<input type="hidden" class="J_FirstPicField" />
																<ul id="J_PanelLocalList">
																	<li>

																		<input type="hidden" class="J_PicUrl" name="picUrl1"
																			id="picUrl1" value="" />
																		<input name="image_pos" type="hidden" value="1" />
																		<span class="preview" id="preview1"></span>
																		<span class="upload"><a href="javascript:;">
																				<s:file name="myfile" id="myfile1"
																					onchange="previewImage('#preview1','myfile1');" />
																		</a> </span>
																		<span class="act"> <span class="moveleft">左移</span>
																			<span class="moveright">右移</span> <span class="del">删除</span>

																		</span>
																	</li>
																	<li>
																		<input type="hidden" class="J_PicUrl" name="picUrl2"
																			value="" />
																		<input name="image_pos" type="hidden" value="2" />
																		<span class="preview" id="preview2"></span>
																		<span class="upload"><a href="javascript:;">
																				<s:file name="myfile" id="myfile2"
																					onchange="previewImage('#preview2','myfile2');" />
																		</a> </span>
																		<span class="act"> <span class="moveleft">左移</span>

																			<span class="moveright">右移</span> <span class="del">删除</span>
																		</span>
																	</li>
																	<li>
																		<input type="hidden" class="J_PicUrl" name="picUrl3"
																			value="" />
																		<input name="image_pos" type="hidden" value="3" />
																		<span class="preview" id="preview3"></span>
																		<span class="upload"><a href="javascript:;">
																				<s:file name="myfile" id="myfile3"
																					onchange="previewImage('#preview3','myfile3');" />
																		</a> </span>

																		<span class="act"> <span class="moveleft">左移</span>
																			<span class="moveright">右移</span> <span class="del">删除</span>
																		</span>
																	</li>
																	<li>
																		<input type="hidden" class="J_PicUrl" name="picUrl4"
																			value="" />
																		<input name="image_pos" type="hidden" value="4" />
																		<span class="preview" id="preview4"></span>
																		<span class="upload"><a href="javascript:;">
																				<s:file name="myfile" id="myfile4"
																					onchange="previewImage('#preview4','myfile4');" />
																		</a> </span>
																		<span class="act"> <span class="moveleft">左移</span>
																			<span class="moveright">右移</span> <span class="del">删除</span>

																		</span>
																	</li>
																	<li>
																		<input type="hidden" class="J_PicUrl" name="picUrl5"
																			value="" />
																		<input name="image_pos" type="hidden" value="5" />
																		<span class="preview" id="preview5"></span>
																		<span class="upload"><a href="javascript:;">
																				<s:file name="myfile" id="myfile5"
																					onchange="previewImage('#preview5','myfile5');" />
																		</a> </span>
																		<span class="act"> <span class="moveleft">左移</span>

																			<span class="moveright">右移</span> <span class="del">删除</span>
																		</span>
																	</li>
																</ul>
															</div>
														</div>
														<div class="msg">
															<span class="orange1 ml5"> 您的图片空间剩余容量为${request.leftSpaceSize }M。
																单个图片大小不能超过500K </span>
														</div>
													</div>
												</div> </span>
										</div>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
					<td></td>
					<td>
						<a href="javascript:checkSubmit();"	class="at_but b_1_y" id="reg_sub"><u></u>确认</a>
					</td>
					</tr>
				</table>
			</div>
			
			<div id="div_contact" style="display: none">
				<table width="660" align="left">
					<tr>
						<td valign="top" rowspan="2" width="150">
							<span id="spanGroups">
							</span>
						</td>
						<td valign="top">
							<table align="center" width="100%" class="tb_datalist" id="tb_memberList">
							</table>
						</td>
					</tr>
					<tr>
						<td align="center">
							<input type="button" name="Submit" id="ok" class="button" value="确 定" onclick="javascript:selectOK();"/>&nbsp;&nbsp;
							<input type="button" name="Return" id="retBtn" class="button" value="返 回" onclick="javascript:window.close();" />
						</td>
					</tr>
				</table>
			</div>
		</s:form>
		   </div> 
		 </div> 
	<div> 
</div>
 <!--主体部分end--> 
</div> 
</div>
<!--底部 start--> 
<%@ include file="/user_button.jsp"%>
<!--底部end--> 
</body> 
</html> 

